package com.yuchen.ishop.service.Order;

import com.yuchen.core.MyPager;
import com.yuchen.ishop.entity.Order;
import com.yuchen.jaxrs.Responses;
import com.yuchen.jaxrs.restclient.RestClientUtils;
import com.yuchen.utils.config.ConfigUtils;
import org.springframework.stereotype.Service;

import javax.ws.rs.core.GenericType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class OrderRestClient {

    public Order insert(Order order) {
        String url = ConfigUtils.config.get("order_insert");
        return  RestClientUtils.post(Order.class, order, url);
    }

    public List<Order> findByOrderNo(String orderNo) {
        String url = ConfigUtils.config.get("order_findByOrderNo");
        Map map = new HashMap(1);
        map.put("orderNo",orderNo);
        url = RestClientUtils.url(url,map);
        GenericType genericType =  new GenericType<List<Order>>() {};
        List<Order> json = RestClientUtils.get(genericType,url);
        return json;
    }

    public MyPager findBySeller(Map map) {
        String url = ConfigUtils.config.get("order_findBySeller");
        return RestClientUtils.post(MyPager.class,map,url);

    }

    public Responses changeOrderPrice(String subOrderNo, Double realPrice) {
        String url = ConfigUtils.config.get("order_changeOrderPrice");
        Map map = new HashMap(2);
        map.put("subOrderNo",subOrderNo);
        map.put("realPrice",realPrice);
        return RestClientUtils.post(Responses.class,map,url);
    }
}
